package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import com.sky.result.PageResult;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    /**
     * 注册员工
     * @param employee
     */
    @AutoFill(OperationType.INSERT)
    @Insert("insert into  employee (id,name, username, password, phone, sex, id_number, create_time, update_time, create_user, update_user) " +
            "VALUES(#{id},#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{createTime},#{updateTime},#{createUser},#{updateUser}) ")
    void register(Employee employee);

    /**
     * 分页查询pageHeaper
     * @param employeePageQueryDTO
     * @return
     */
    Page<Employee> pageSelect(EmployeePageQueryDTO employeePageQueryDTO);

    /**
     * 使用limit分页查询
     * @param index
     * @param pageSize
     * @return
     */
    @Select("select *from employee order by name desc limit  #{index},#{pageSize}")
    List<Employee> pageSelectByLimit(int index, int pageSize);
    @Select("select count(*)from employee")
    Integer selectTotal();

    /**
     * 修改员工数据
     * @param employee
     */
    @AutoFill(OperationType.UPDATE)
    void update(Employee employee);

    /**
     * 根据id查询数据
     * @param id
     * @return
     */
    @Select("select *from employee where id=#{id}")
    Employee selectByid(Long id);


}
